import { Modal, Input, Form, message, Spin } from 'antd';
import React from 'react';
import { connect } from 'dva';

const FormItem = Form.Item;

class DataDetail extends React.Component {
  Save() {
    this.props.form.validateFields((err, values) => {
      this.props.dispatch({
        type: 'data/insetorupdate',
        data: values
      }).then(res => {
        if (res.RESULT) {
          message.success("Successful");
          this.props.showModel(false);
          this.props.form.resetFields();
          this.props.loadData();
        } else {
          message.error("Fail");
        }
      })

    })
  }
  render() {
    const { getFieldDecorator } = this.props.form;
    const formItemLayout = { labelCol: { span: 8 }, wrapperCol: { span: 14 }, layout: "horizontal" };
    return (
      <Modal
        title="Data Details"
        centered
        visible={this.props.visible}
        onOk={this.Save.bind(this)}
        onCancel={() => { this.props.showModel(false); this.props.form.resetFields(); }}
      >
        <Spin spinning={!!this.props.loading.models.data}>
          {/* <Form layout="horizontal" labelCol={{ span: 6 }} wrapperCol={{ span: 14 }} >          */}
          <Form {...formItemLayout}>
            <FormItem style={{ display: "none" }} label="ID"> {getFieldDecorator('ID', { initialValue: this.props.data.ID })(<Input />)}</FormItem>
            <FormItem label="CPYW"> {getFieldDecorator('CPYW', { initialValue: this.props.data.CPYW })(<Input />)}</FormItem>
            <FormItem label="PROBLEMTYPE"> {getFieldDecorator('PROBLEMTYPE', { initialValue: this.props.data.PROBLEMTYPE })(<Input />)}</FormItem>
            <FormItem label="PROBLEMTYPESUB"> {getFieldDecorator('PROBLEMTYPESUB', { initialValue: this.props.data.PROBLEMTYPESUB })(<Input />)}</FormItem>
            <FormItem label="FLAWCode"> {getFieldDecorator('FLAWCode', { initialValue: this.props.data.FLAWCode })(<Input />)}</FormItem>
          </Form>
        </Spin>
      </Modal>
    );
  }
}

export default connect(
  ({ loading }) => {
    return { loading };
  })(Form.create({})(DataDetail));